package conversion;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

public class MyDateConversion extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
		Date ret = null;
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			ret = sf.parse(arg1[0]);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ret;
	}

	@Override
	public String convertToString(Map arg0, Object date) {
		
		String ret = "";
		if(date!=null){
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			ret = sf.format(date);
		}
		
		return ret;
	}

}
